package collections;

import java.util.*;

public class ReversibleArrayList <T> extends ArrayList<T> {
    ReversibleArrayList(Collection<T> c){
        super(c);
    }
    public Iterable<T> reversed(){
        return new Iterable<T>() {
            public Iterator<T> iterator() {
                return new Iterator<T>() {
                    int current = size() -1;
                    public boolean hasNext(){
                        return current>-1;
                    }

                    public T next(){
                        return get(current--);
                    }
                    public void remove(){
                        throw new UnsupportedOperationException();
                    }

                };
            }
        };
    }
}

